import datetime
from haystack import indexes
from apps.goods.models import SKU,SPU

# 1. 类 必须继承自 indexes.SearchIndex, indexes.Indexable
# 2. 类名和模型类名一致
class SKUIndex(indexes.SearchIndex, indexes.Indexable):
    # 3. text 惯例是命名字段text
    text = indexes.CharField(document=True, use_template=True)
    # author = indexes.CharField(model_attr='user')
    # pub_date = indexes.DateTimeField(model_attr='pub_date')
    # 4. 方法 指定模型
    def get_model(self):
        return SKU
    # 5. 让模型查询数据 将查询的数据给haystack
    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(is_launched=True)
